<template>
  <Row type="flex">
    <Col flex="600px"> <h2 class="title2">质量监督 <i>{{ config.page.total }}</i></h2></Col>
    <Col flex="550px"></Col>
  </Row>

  <Table
      :columns="config.columns"
      :row-key="(record,index) => index"
      :data-source="config.list"
      :pagination="config.page"
      :loading="config.loading"
      @change="(pagination)=> changeHandler(pagination, config)"
      bordered
  >
    <template #indexSlot="{ index }">{{(config.page.current-1)*10+index+1}}</template>
    <template #name="{ text, record }">
      <router-link target="_blank" :to="{ path: `/activity/${record.activityId}` }" class="blue" >
        {{ text }}
      </router-link>
    </template>
  </Table>
</template>

<script lang="ts">
import {defineComponent, inject, onMounted, reactive,  toRefs} from 'vue';
import {Row, Col, Table } from 'ant-design-vue';
import {  getActivityQualityApi  } from '/@/api/activity';
import { parseTime } from '/@/utils';
const columns = [
  { title: '序号', dataIndex: 'index', width: 70, align: 'center', slots: ({ customRender: 'indexSlot' }) },
  { title: '工程名称', dataIndex: 'singleName',width: 250},
  { title: '质量监督注册号', dataIndex: 'regNo',width: 250},
  { title: '报监日期', dataIndex: 'applyDate',width: 180,customRender: ({ record })=> parseTime(record.applyDate)},
  { title: '质量监督机构', dataIndex: 'unit'}
]

export default defineComponent({
  components: {
    Table , Row, Col
  },
  setup() {
    const activityId = inject('activityId') as string;
    const config = reactive({

      columns: columns,
      list: [],
      loading: false,
      page: {
        total: 0,
        current: 1
      }
    })

    const changeHandler = (pagination, config) => {
      const { current } = pagination;
      let { loading, list, page } = toRefs(config);
      loading.value = true;
      const params = { activityId, current , type: '1' };
      getActivityQualityApi(params).then(({data ,success}) => {
        if(success){
          let { records, current, total } = data;
          list.value = records;
          loading.value = false;
          page.value = {current, total};
        }
      })
    }
    const init = () => {
      changeHandler({current: 1}, config);
    }
    onMounted(init)
    return {
      config, changeHandler
    }
  },
})
</script>

<style lang="less" scoped>

.ant-col{
  padding-top: 24px;
  margin-bottom: 12px;
}

.ant-select ,.ant-btn{
  width: 100%;
}

.ant-col.text-right{
  padding-right: 0 !important;
}

</style>
